package com.cskaoyan._05servlet_3forwordredirect;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author Macro_Ray
 * @since 2024/5/3 下午9:53
 */
// 请求转发A
@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ServletA 执行了");

        // 请求转发
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("servletB");    // 转发到 servletB
        // RequestDispatcher requestDispatcher = reg.getRequestDispatcher("a.html");          // 可以访问工程的资源文件
        // RequestDispatcher requestDispatcher = reg.getRequestDispatcher("WEB-INF/b.html");  // 可以访问受保护的 WEB-INF 目录下文件
        // RequestDispatcher requestDispatcher = reg.getRequestDispatcher("http://www.atguigu.com");  // 不能访问外部资源



        requestDispatcher.forward(request, response);     // 做出转发请求的动作

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
